/**
 * <p><b>Title:</b> PcOperateLogController.java </p>
 * @Package com.wondertek.oes.charge.service.controller
 */
package com.wondertek.poms.log.controller;

import java.time.LocalDateTime;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.wondertek.poms.common.controller.BaseController;
import com.wondertek.poms.common.vo.PageBean;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.service.IPcOperateLogService;
import com.wondertek.poms.dao.po.PcOperateLog;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * <p><b>PcOperateLogController Description:</b> 操作日志表Controller层实现</p>
 * @author 窦再兴
 * <p><b>DATE</b> 2019-08-12 12:45:35</p>
 */
@Api(value="PcOperateLogController", description="俱乐部基本信息表接口")
@RestController
@Scope("prototype")
@RequestMapping(value="/pc-operate-log")
public class PcOperateLogController extends BaseController {
	
	@Autowired
	private IPcOperateLogService pcOperateLogService;
	
	@ApiOperation(value="操作日志列表", notes="操作日志列表")
	@GetMapping("/list")
	@ResponseBody
	public ResultBean list(HttpServletRequest request,
			PcOperateLog pcOperateLog,
			@RequestParam(defaultValue="1") int page, 
			@RequestParam(defaultValue="20") int rows,
			@RequestParam(defaultValue="createdTime") String sidx, 
			@RequestParam(defaultValue="desc") String sord) {
		Page<PcOperateLog> pages = pcOperateLogService
				.findLike(pcOperateLog, page, rows, sord, sidx);
		
		return PageBean.ok(pages.getTotalPages(), pages.getTotalElements(), pages.getContent());
	}

	@ApiOperation(value="操作日志新增", notes="操作日志新增")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "ip", required = true),
		@ApiImplicitParam(name = "userName", required = true),
		@ApiImplicitParam(name = "model", required = true),
		@ApiImplicitParam(name = "url", required = true),
		@ApiImplicitParam(name = "params", required = true),
		@ApiImplicitParam(name = "opterate", required = true),
		@ApiImplicitParam(name = "flag", required = true),
		@ApiImplicitParam(name = "createdTime", required = true),
	})
	@PostMapping(value = "/add")
	@ResponseBody
	public ResultBean add(@RequestBody PcOperateLog log) {
		if (log.getCreatedTime() == null) {
			log.setCreatedTime(LocalDateTime.now());
		}
		if (log.getExceptionFlag() == null) {
			log.setExceptionFlag(Boolean.FALSE);
		}
		PcOperateLog.putTimeAndUser(log);
		pcOperateLogService.save(log);
		return ResultBean.ok(log);
	}
	
	@ApiOperation(value="操作日志详情", notes="操作日志详情")
	@ApiImplicitParam(name = "id", required = true, paramType = "query", dataType = "Long")
	@GetMapping(value = "/get")
	@ResponseBody
	public ResultBean get(Long id) {
		PcOperateLog pcOperateLog = pcOperateLogService.get(id);
		return ResultBean.ok(pcOperateLog);
	}
	
	@ApiOperation(value="操作日志删除", notes="操作日志删除")
	@ApiImplicitParam(name = "id", required = true, paramType = "query", dataType = "Long")
	@DeleteMapping(value = "/del")
	@ResponseBody
	public ResultBean delete(Long id) {
		pcOperateLogService.deleteById(id);
		return ResultBean.ok();
	}
}
